#ifndef FIELDVALIDATOR_H
#define FIELDVALIDATOR_H

#include <QWidget>
#include <QLineEdit>
#include <QPushButton>

/*!
 * @class FieldValidator
 * @brief Checks fields contained in a widget for valid information.
 *
 * The FieldValidador class checks the added field widgets (QLineEdit)
 * contained within a specified widget for blank fields. Blank fields
 * (line edit objects with no text) are colored red to indicate to the user
 * that they need to be filled. The class can also disable a button (a submit
 * button, for example) until all fields are filled.
 */

class FieldValidator : public QWidget
{
    Q_OBJECT

public:
    /*! @param parent The widget that contains the field widgets to validate.*/
    FieldValidator(QWidget *parent);

    /*! Adds every field (QLineEdit) found in the parent widget to the list of
     *  widgets to check.
     */
    void addAllFields();

    /*! Set button to disable if not all fields are filled, or to enable once
     *  every field is filled. This would be used for a form submit button,
     *  for example.
     */
    void setButton(QPushButton *button);

    /*! Changes every field back to valid color (until a field is changed) and
     *  blanks all fields.
     */
    void resetFields();

public slots:
    void check_fields(QString);

private:
    bool formValid;

    QPushButton *button;
	QPalette redPalette, whitePalette;

    QList<QLineEdit *> widgetList;
};

#endif // FIELDVALIDATOR_H
